package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.DealershipDAO;
import edu.byu.intex2.data.dao.ServiceFacilityDAO;

/**
 * Dealership represents a car dealership with physical car inventory.
 * @author Brady White
 */
public class Dealership extends BusinessObject {
    private String address;
    private String phone;

    /** Service Facility */
    private String serviceFacilityId;
    private ServiceFacility serviceFacility;

    /** Creates a new instance of BusinessObject */
    public Dealership(String id) {
        super(id);
    }//constructor

    /** Convenience method to call the correct DAO to save this business object */
    public void save() throws DataException {
        try {
            DealershipDAO.getInstance().save(this);
        } catch (DataException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
        setDirty(true);
    }

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
        setDirty(true);
    }


    /**
     * @return the serviceFacilityId
     */
    public String getServiceFacilityId() {
        return serviceFacilityId;
    }

    /**
     * @param serviceFacilityId the serviceFacilityId to set
     */
    public void setServiceFacilityId(String serviceFacilityId) {
        this.serviceFacilityId = serviceFacilityId;
        setDirty();
    }

    /**
     * @return the serviceFacility from the DAO
     */
    public ServiceFacility getServiceFacility() {
        if (serviceFacility == null) {
            try {
                serviceFacility = ServiceFacilityDAO.getInstance().read(serviceFacilityId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return serviceFacility;
    }

    /**
     * @param serviceFacility the serviceFacility to set
     */
    public void setServiceFacility(ServiceFacility serviceFacility) {
        this.serviceFacility = serviceFacility;
    }

}
